﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RedHouse.Data;
using RedHouse.Data.Base;
using RedHouse.Data.Common;
namespace RedHouse.AdminControl
{
    public partial class Gallery : System.Web.UI.Page
    {
        public Guid AssociatedId { get; set; }
        public Detail GalleryOwner { get; set; }
        public string Category { get; set; }
        public List<RedHouse.Data.Image> ImageList { get; set; }
        public string Message { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            btnAdd.Click += new EventHandler(btnAdd_Click);
            
                string id = Request.QueryString["id"];
                Category = Request.QueryString["category"];
                if (!string.IsNullOrEmpty(id))
                {
                    AssociatedId = new Guid(id);
                    Initialize();
                }
        }

        void btnAdd_Click(object sender, EventArgs e)
        {
            RedHouse.Data.Image image = new Data.Image()
            {
                ID = Guid.NewGuid(),
                AssociatedID = this.AssociatedId,
                CreatedDate = DateTime.Now,
                Url = txtUrl.Text,
                CreatedBy = "admin"
            };
            OperationResult result = ImageService.Instance.SaveImage(image);
            Message = result.Message;
            if (result.Result)
            {
                SuccessPanel.Visible = true;
                ImageList = ImageService.Instance.GetAllImageByAssociatedId(AssociatedId);
            }
            else
            {
                ErrorPanel.Visible = true;
            }
        }

        private void Initialize()
        {
            Message = string.Empty;
            ErrorPanel.Visible = false;
            SuccessPanel.Visible = false;

            GalleryOwner = DetailService.Instance.GetDetailByAssociatedID(AssociatedId);
            ImageList = ImageService.Instance.GetAllImageByAssociatedId(AssociatedId);
        }
    }
}